package pannelli.main;
import it.jack.PannelloPrincipale;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;

import com.cloudgarden.layout.AnchorConstraint;
import com.cloudgarden.layout.AnchorLayout;
import it.jack.Main;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;

import javax.swing.WindowConstants;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;

import pannelli.sub.SubPannelloVisualizzaRiparazione;


public class PannelloRiparazioni extends JInternalFrame implements InternalFrameListener{
	
	private static final long serialVersionUID = 1L;
	private JButton ricerca;
	private PannelloRicerca pannelloRicerca;
	private static PannelloRiparazioni instance;

	public void setFlag(boolean flag){
		SubPannelloVisualizzaRiparazione.getInstance().setFlag(flag);
	}
	public void updateTable(){
		SubPannelloVisualizzaRiparazione.getInstance().initTable();
	}
	public PannelloRiparazioni() throws PropertyVetoException {
		super("Pannello Riparazioni",true,true,true,true);
		this.instance=this;
		initGUI();
		buttonAction();
		centra();
		setVisible(true);
		setSelected(true);
		this.addInternalFrameListener(this);
	}
	public static PannelloRiparazioni getInstance(){
		return instance;
	}
	public void centra(){
		Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation(new Point((dimension.width - getSize().width) / 2, 
				(dimension.height - getSize().height) / 2 ));

	}
	private void initGUI() {
		try {
			AnchorLayout thisLayout = new AnchorLayout();
			getContentPane().setLayout(thisLayout);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setPreferredSize(new java.awt.Dimension(800, 700));
			{
				ricerca = new JButton();
				getContentPane().add(ricerca, new AnchorConstraint(348, 979, 451, 813, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				ricerca.setText("Ricerca");
				ricerca.setPreferredSize(new java.awt.Dimension(126, 36));
				
			}
			{
                                SubPannelloVisualizzaRiparazione.getInstance().init(-1);
				getContentPane().add(SubPannelloVisualizzaRiparazione.getInstance(), new AnchorConstraint(1, 789, 1001, 0, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				SubPannelloVisualizzaRiparazione.getInstance().setPreferredSize(new java.awt.Dimension(597, 349));
			}
			pack();
			this.setSize(757, 371);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private void buttonAction(){
		
		ricerca.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				pannelloRicerca = new PannelloRicerca(1);
				try {
					pannelloRicerca.setSelected(true);
					Main.getInstance().addInDesktop(pannelloRicerca);
				} catch (PropertyVetoException e1) {
					e1.printStackTrace();
				}
			}
		});
		
	}
	@Override
	public void internalFrameActivated(InternalFrameEvent arg0) {
		PannelloPrincipale.getIstance().disableButtons();
	}
	@Override
	public void internalFrameClosed(InternalFrameEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void internalFrameClosing(InternalFrameEvent arg0) {
		PannelloPrincipale.getIstance().activateButtons();
		this.dispose();
	}
	@Override
	public void internalFrameDeactivated(InternalFrameEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void internalFrameDeiconified(InternalFrameEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void internalFrameIconified(InternalFrameEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void internalFrameOpened(InternalFrameEvent arg0) {
		PannelloPrincipale.getIstance().disableButtons();
	}
}
